package ua.cs.stu.ics.GUI;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ua.cs.stu.ics.dao.dbf.StudentDAO;
import ua.cs.stu.ics.dbf.DBReaderFactory;
import ua.cs.stu.ics.dbf.domain.StudentDomain;

import java.util.ArrayList;


public class ConnectClass {

    private DBReaderFactory dBReaderFactory;
    private StudentDAO studentDAO;

    public DBReaderFactory getdBReaderFactory() {
        return dBReaderFactory;
    }

    public void setdBReaderFactory(DBReaderFactory dBReaderFactory) {
        this.dBReaderFactory = dBReaderFactory;
    }

    public StudentDAO getStudentDAO() {
        return studentDAO;
    }

    public void setStudentDAO(StudentDAO studentDAO) {
        this.studentDAO = studentDAO;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("context.xml");
        ConnectClass cc = new ConnectClass();
        cc.setdBReaderFactory((DBReaderFactory) applicationContext.getBean("dBReaderFactory"));
        cc.setStudentDAO((StudentDAO) applicationContext.getBean("studentDAO"));
        cc.viewStudents();

    }

    public void viewStudents(){
        dBReaderFactory.init();
        ArrayList<StudentDomain> as = (ArrayList<StudentDomain>) studentDAO.findAll();
        for (StudentDomain sd: as){
            System.out.println(sd.getFio());
        }

    }

}
